function formatTime(dateTime) {
    if (!typeof dateTime == "Date") {
        dateTime = new Date(dateTime);
    }
    const hour = date.getHours()
    const minute = date.getMinutes()
    // console.log(hour + ":" + minute)
    return hour + ":" + minute;
}
const formatDateTime = date => {
    console.log(typeof date);
    if (typeof date != "Date") {
        date = new Date(date);
    }
    console.log(date);
    const year = date.getFullYear();
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatDate = function(date, para) {
    console.log(typeof date);
    if (typeof date != "Date") {
        date = new Date(date);
    }
    console.log(date);
    const year = date.getFullYear();
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    let dateArr = [],
        timeArr = [];
    if (para.indexOf('yyyy') != -1) {
        dateArr.push(year);
    }
    if (para.indexOf('MM') != -1) {
        dateArr.push(month);
    }
    if (para.indexOf('dd') != -1) {
        dateArr.push(day);
    }
    if (para.indexOf('HH') != -1) {
        timeArr.push(hour);
    }
    if (para.indexOf('mm') != -1) {
        timeArr.push(minute);
    }
    if (para.indexOf('ss') != -1) {
        timeArr.push(second);
    }
    let spl = '-';
    if (para.indexOf('/') != -1) {
        spl = '/';
    }
    return dateArr.map(formatNumber).join(spl) + ' ' + timeArr.map(formatNumber).join(':');
    //"yyyy/MM/dd HH:mm:ss" 
}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}
const log = (msg) => {
    console.log(msg);
}

// 校验车牌
function checkCarBrand(str) {
    var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/

    if (reg.test(str)) {
        return true
    } else {
        return false;
    }
}
// 校验手机号
function checkPhone(str) {
    if (str === undefined || str === '') {
        return false
    }
    var reg = /^1[0-9]{10}$/
    if (reg.test(str)) {
        return true
    } else {
        return false
    }
}

module.exports = {
    formatDateTime: formatDateTime, //获得接口地址
    formatTime: formatTime,
    formatDate: formatDate,
    checkCarBrand: checkCarBrand,
    checkPhone: checkPhone,
    log: log,
    ALL_ORDER: 0,
    WAIT_ORDER: 1,
    SERVERING_ORDER: 2,
    FINSH_ORDRE: 3,
    CANCEL_ORDER: 4
}